<?php
namespace lib;
/**
 * Created by PhpStorm.
 * User: gc
 * Date: 2017/8/29
 * Time: 0:56
 */
class v{
    public static $_self;
    public static function i($pars = [])
    {
        self::$_self or self::$_self = new \lib\v();
        return self::$_self;
    }
    public $tpl_ary=[];
    public $val_ary=[];
    public $return_str=false;
    public $outhtml='';
    public function tpl_ary($tpl_ary=[])
    {
        $this->tpl_ary=$tpl_ary;
        return $this;
    }
    public function val_ary($val_ary=[])
    {
        $this->val_ary=$val_ary;
        return $this;
    }
    public function return_str($return_str)
    {
        $this->return_str=$return_str;
        return $this;
    }
    private function stru_html()
    {
        ob_start();
        extract($this->val_ary);
        foreach($this->tpl_ary as $k=>$v){
            $file_path=D."/app/v/".$v.".php";
            if(!is_file($file_path))
            {
                continue;//如果不存在文件就跳过
            }
            require($file_path);
        }
        $ret=ob_get_clean();
        $this->outhtml=$ret;
        return $this->outhtml;
    }


    public function e()
    {
        $ret=$this->stru_html();
        if($this->return_str)
        {
            return $ret;
        }else{
            echo $ret;
        }
    }
}